std::unique_ptr

From Cppreference

Jump to: navigation, search
Defined in header <memory>

template<

    class T,
    class Deleter = std::default_delete<T>

> class unique_ptr;
(C++11 feature)

std::unique_ptr is a smart pointer that retains sole ownership of an object through a pointer. The unique_ptr can not be copied, thus it is guaranteed to be the only unique_ptr referring to that object. When the unique_ptr is destroyed, it disposes of the object through its deleter.

Contents

[edit] Member types

Member type Definition
pointer std::remove_reference<D>::type::pointer if that type exists, otherwise T*
element_type T
deleter_type Deleter

[edit] Member functions

Member functions

(constructor)
constructs new unique_ptr
(public member function)
(destructor)
destructs the managed object if such is present
(public member function)
operator=
assigns the unique_ptr
(public member function)
Modifiers
release
returns a pointer to the managed object and releases the ownership
(public member function)
reset
replaces the managed object
(public member function)
swap
swaps the managed objects
(public member function)
Observers
get
returns a pointer to the managed object
(public member function)
get_deleter
returns the deleter that is used for destruction of the managed object
(public member function)
operator*
operator->
dereferences pointer to the managed object
(public member function)
operator bool
checks if there is associated managed object
(public member function)

[edit] Non-member functions

std::swap(unique_ptr) (C++11)
specializes the std::swap() algorithm
(function template)
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox
In other languages